import React from 'react';
import { Http, BeanUtils } from './../common/Utils';
import { CrudTable, Toolbar, EditForm, Crud } from './../common/Crud';
import { Modal, Buttonm, Divider } from 'antd';

const fileds = [
    {
        name: 'id',
        type: 'hidden'
    }, {
        name: 'status',
        type: 'hidden'
    }, {
        name: 'name',
        label: '名称',
        type: 'text',
        option: {
            rules: [
                { required: true, message: '请输入' }
            ]
        }
    }, {
        name: 'resourceIds',
        label: '拥有权限',
        type: 'tree',
        option: {
            data : '/api/authority/resources.json'
        }
    }
];

/**
 * 幻灯片管理
 */
class Role extends Crud {

    state = {
        url: '/api/banner',

        formModalWidth: 1000,

        /*******************搜索框***************** */
        searchField: [
            {
                name: 'type',
                label: '位置',
                type: 'select',
                options: [
                    { label: '全部', value: 0 },
                    { label: '首页', value: 1 }
                ]
            }, {
                name: 'name',
                label: '名称',
                type: 'text'
            }
        ],

        /*******************列表***************** */
        columns: [{
            title: '名称',
            dataIndex: 'name',
            sorter: true
        }, {
            title: '状态',
            dataIndex: 'status',
            render: (v, record, index) => {
                if (v == '0') {
                    return '已禁用';
                } else if (v == '1') {
                    return '已启用';
                } else {
                    return '-';
                }
            }
        }, {
            title: '创建时间',
            dataIndex: 'createdtime'
        }, {
            title: '操作',
            dataIndex: 'id',
            render: (v, record, index) => {
                return (
                    <div>
                        {
                            record.status == '1' ?
                                <a onClick={() => this.changeStatus('0', record)}>禁用</a> :
                                <a onClick={() => this.changeStatus('1', record)}>启用</a>
                        }
                        <Divider type="vertical" />
                        <a onClick={() => this.onEdit(record)}>编辑</a>
                        <Divider type="vertical" />
                        <a onClick={() => this.onDeletet(record)}>删除</a>
                    </div>
                )
            }
        }],

        /*******************编辑表单***************** */
        addFields: BeanUtils.copy(fileds),
        editFields: BeanUtils.copy(fileds)
    }
}

export default Role;
